package net.lab1024.sa.admin.module.business.category.domain.dto;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import lombok.Data;
import net.lab1024.sa.admin.module.business.category.domain.entity.OperationLog;

import java.time.format.DateTimeFormatter;

@Data
@HeadRowHeight(25) // 表头行高
@ColumnWidth(15) // 默认列宽
public class OperationLogExportDTO {
    @ExcelProperty(value = "序号", index = 0)
    @ColumnWidth(8)
    private Integer serialNumber;

    @ExcelProperty(value = "姓名", index = 1)
    private String operatorName;

    @ExcelProperty(value = "学工号", index = 2)
    private String operatorCode;

    @ExcelProperty(value = "手机号", index = 3)
    @ColumnWidth(15)
    private String operatorPhone;

    //    @ExcelProperty(value = "班级", index = 4)
    //    @ColumnWidth(20)
    //    private String className;

    @ExcelProperty(value = "操作模块", index = 4)
    private String module;

    @ExcelProperty(value = "操作内容", index = 5)
    @ColumnWidth(30)
    private String operation;

    @ExcelProperty(value = "结果", index = 6)
    @ColumnWidth(10)
    private String result;

    @ExcelProperty(value = "操作时间", index = 7)
    @ColumnWidth(20)
    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
    private String createTime;

    public OperationLogExportDTO(int serialNumber, OperationLog log) {
        this.serialNumber = serialNumber;
        this.operatorName = log.getOperatorName();
        this.operatorCode = log.getOperatorCode();
        this.operatorPhone = log.getOperatorPhone();
        this.module = log.getModule();
        this.operation = log.getOperation();
        this.result = log.getResult();
        this.createTime = log.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
    }
}